package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.CollectionChainRecord;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.UserChainAddr;
import com.sc.nft.mapper.UserChainAddrMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_user_chain_addr)数据DAO
 *
 * @author Sun
 * @since 2022-06-22 16:53:33
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class UserChainAddrDao extends ServiceImpl<UserChainAddrMapper, UserChainAddr> {

    public UserChainAddr getOneByUserIdAndBlockChainId(Long userId, Long blockChainId) {
        LambdaQueryWrapper<UserChainAddr> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserChainAddr::getUserId,userId);
        wrapper.eq(UserChainAddr::getBlockChainId,blockChainId);
        wrapper.last("order by id desc limit 1");
        return getOne(wrapper);
    }


    public UserChainAddr getByUserId(Long userId) {
        LambdaQueryWrapper<UserChainAddr> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserChainAddr::getUserId,userId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public Page<CollectionChainRecord> getCollectionChainRecord(Long userId, int pageNo, int pageSize) {
        return baseMapper.getCollectionChainRecord(new Page(pageNo,pageSize),userId);
    }
    public Page<CollectionChainRecord> getToUserIdCollectionChainRecord(Long userId, int pageNo, int pageSize) {
        return baseMapper.getToUserIdCollectionChainRecord(new Page(pageNo,pageSize),userId);
    }
}